package com.marketingcenter.common;

/**
 * 状态码枚举类
 * 定义系统中所有可能的响应状态码
 */
public enum StatusCodeEnum {

    // 成功相关状态码
    SUCCESS(200, "成功"),
    CREATED(201, "创建成功"),
    ACCEPTED(202, "已接受"),
    NO_CONTENT(204, "无内容"),

    // 客户端错误相关状态码
    BAD_REQUEST(400, "请求错误"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "方法不允许"),
    NOT_ACCEPTABLE(406, "不接受"),
    CONFLICT(409, "冲突"),
    GONE(410, "已删除"),
    UNSUPPORTED_MEDIA_TYPE(415, "不支持的媒体类型"),
    UNPROCESSABLE_ENTITY(422, "无法处理的实体"),

    // 服务器错误相关状态码
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    NOT_IMPLEMENTED(501, "未实现"),
    BAD_GATEWAY(502, "网关错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),

    // 业务错误相关状态码
    BUSINESS_ERROR(1000, "业务错误"),
    PARAM_ERROR(1001, "参数错误"),
    VALIDATION_ERROR(1002, "验证失败"),
    DATA_ERROR(1003, "数据错误"),
    AUTH_ERROR(1004, "认证错误"),
    PERMISSION_ERROR(1005, "权限错误"),
    RESOURCE_ERROR(1006, "资源错误"),
    NETWORK_ERROR(1007, "网络错误"),
    TIMEOUT_ERROR(1008, "超时错误"),
    CONFIG_ERROR(1009, "配置错误"),

    // 营销相关业务错误
    PROMOTION_NOT_FOUND(2001, "营销活动不存在"),
    PROMOTION_EXPIRED(2002, "营销活动已过期"),
    PROMOTION_NOT_STARTED(2003, "营销活动未开始"),
    PROMOTION_DISABLED(2004, "营销活动已禁用"),
    PROMOTION_LIMIT_REACHED(2005, "营销活动次数已达上限"),
    USER_LIMIT_REACHED(2006, "用户已达领取上限"),
    COUPON_NOT_FOUND(2007, "优惠券不存在"),
    COUPON_EXPIRED(2008, "优惠券已过期"),
    COUPON_USED(2009, "优惠券已使用"),
    COUPON_INELIGIBLE(2010, "优惠券不满足使用条件"),
    DISCOUNT_CARD_NOT_FOUND(2011, "折扣卡不存在"),
    COUNT_CARD_NOT_FOUND(2012, "次数权益卡不存在"),
    COUNT_INSUFFICIENT(2013, "剩余次数不足"),
    PACKAGE_CARD_NOT_FOUND(2014, "套餐卡不存在");

    private final int code;
    private final String message;

    StatusCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    /**
     * 根据状态码获取枚举实例
     */
    public static StatusCodeEnum getByCode(int code) {
        for (StatusCodeEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return INTERNAL_SERVER_ERROR;
    }

    @Override
    public String toString() {
        return "StatusCodeEnum{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}